package com.jinzhi.jzweb.controller.modelConfig;


import java.util.*;

import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.ProductTypeDO;
import com.jinzhi.jzweb.service.ProductTypeService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 商品类型表
 * </pre>
 * <small> 2024-09-18 16:03:15 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/productType")
@Api(value = "商品类型管理", tags = {"商品类型管理"})
public class ProductTypeController extends BaseController {

	private final ProductTypeService productTypeService;
	public ProductTypeController(ProductTypeService productTypeService){
		this.productTypeService = productTypeService;
	}


	@ApiOperation(value = "页面地址", notes = "页面地址 权限：jzweb:productType:productType")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping()
	@RequiresPermissions("jzweb:productType:productType")
	String ProductType(){
	    return "jzweb/productType/productType";
	}



	@ApiOperation(value = "商品类型分页列表", notes = "商品类型分页列表")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@ResponseBody
	@PostMapping("/list")
	public Result<Page<ProductTypeDO>> list(ProductTypeDO productTypeDTO){

        return Result.ok(productTypeService.productList(productTypeDTO));
	}



	@ApiOperation(value = "新增页面地址", notes = "新增页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/add")
	String add(){
	    return "jzweb/productType/add";
	}



	@ApiOperation(value = "详情页面地址", notes = "详情页面地址")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@GetMapping("/edit/{id}")
	String edit(@PathVariable("id") Long id,Model model){
		ProductTypeDO productType = productTypeService.selectById(id);
		model.addAttribute("productType", productType);
	    return "jzweb/productType/edit";
	}


	@ApiOperation(value = "新增商品类型", notes = "新增商品类型")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@ResponseBody
	@PostMapping("/save")
	public Result<String> save(@RequestBody ProductTypeDO productType){
		productType.setCreaterId(this.getUserId());
		productTypeService.insert(productType);
        return Result.ok();
	}



	@ApiOperation(value = "修改商品类型", notes = "修改商品类型")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@ResponseBody
	@PostMapping("/update")
	public Result<String>  update(@RequestBody ProductTypeDO productType){
		productType.setUpdaterId(this.getUserId());
		boolean update = productTypeService.updateById(productType);
		return update ? Result.ok() : Result.fail();
	}



	@ApiOperation(value = "删除商品类型", notes = "删除商品类型")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@PostMapping( "/remove")
	@ResponseBody
	public Result<String>  remove(@RequestParam("id") Long id){
		productTypeService.deleteById(id);
        return Result.ok();
	}



	@ApiOperation(value = "批量删除删除商品类型", notes = "批量删除删除商品类型")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@PostMapping( "/batchRemove")
	@ResponseBody
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		productTypeService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}


	@ApiOperation(value = "禁用商品类型", notes = "禁用商品类型(state：0.启动/1.禁用)")
	@ApiImplicitParams({
	})
	@ApiResponses({
			@ApiResponse(code = 0, message = "操作成功")
	})
	@PostMapping( "/disable")
	@ResponseBody
	public Result<String>  disable(@RequestParam("id") Long id,@RequestParam("state") Integer state){
		ProductTypeDO productTypeDO = new ProductTypeDO();
		productTypeDO.setId(id);
		productTypeDO.setState(state);
		productTypeService.updateById(productTypeDO);
		return Result.ok();
	}
	
}
